//
//  TCLYBillViewController.m
//  YuErmuYing
//
//  Created by LYang on 16/9/26.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYBillViewController.h"
#import "TCLYWalletTableViewCell.h"
#import "TCLYUser.h"
#import "TCLYMineModel.h"
#import "Macros.h"
#import "Masonry.h"

@interface TCLYBillViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView * billTableView;
@property (nonatomic, strong) TCLYUser * user;
@property (nonatomic, strong) TCLYMineModel * mineModel;
@end

@implementation TCLYBillViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(walletDetail) name:@"walletDetail" object:nil];
    self.user = [[TCLYUser alloc] init];
    self.mineModel = [[TCLYMineModel alloc] init];
    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys: self.user.userId, @"uid", nil];
    [self.mineModel walletDetailParameter:dic];
    [self createTitleView];
    [self createView];
}
-(void) createView{
    self.billTableView = [[UITableView alloc] init];
    self.billTableView.dataSource = self;
    self.billTableView.delegate = self;
    [self.billTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.billTableView.backgroundColor = bgColor;
    [self.view addSubview:self.billTableView];
    [self.billTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.mineModel.walletDetailArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier = @"walletDetailCell";
    TCLYWalletTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[TCLYWalletTableViewCell alloc] initWithReuseIdentifier:identifier];
    }
    cell.typeLabel.text = self.mineModel.walletDetailArr[indexPath.row][@"type"];
    cell.timeLabel.text = self.mineModel.walletDetailArr[indexPath.row][@"time"];
    cell.moneyLabel.text = self.mineModel.walletDetailArr[indexPath.row][@"cash"];
    return cell;
}
-(void)walletDetail{
    [self.billTableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)createTitleView{
    self.navigationController.navigationBar.barStyle = UIBarMetricsCompactPrompt;
    self.navigationController.navigationBar.backgroundColor = statusColor;
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, -20, screenWidth, 20)];
    view.backgroundColor = navColor;
    [self.navigationController.navigationBar addSubview:view];
    
    UILabel * titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"明细";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.frame = CGRectMake(0, 0, 50, 20);
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = titleLabel;
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(12, 22, 20, 20);
    [leftBtn setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
    leftBtn.tag = 91;
    [leftBtn addTarget:self action:@selector(statusBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
}
-(void)statusBtnAction:(id)sender{
    switch (((UIButton *)sender).tag) {
        case 91:{
            [self.navigationController popViewControllerAnimated:YES];
            self.navigationController.navigationBarHidden = NO;
            self.tabBarController.tabBar.hidden = YES;
        }
            break;
        case 92:{
            
        }
            break;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
